﻿using SiliconSelect.BLL;
using SiliconSelect.Common;
using SiliconSelect.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SiliconSelect.Views
{
    /// <summary>
    /// SlaveControlView.xaml 的交互逻辑
    /// </summary>
    public partial class SlaveControlView : UserControl
    {
        public SlaveControlView()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 监听左键,单击左键
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox checkBox = (sender as CheckBox)!;
            string boxName = checkBox.Content.ToString()!;
            bool isChecked = checkBox.IsChecked!.Value;
            // 确实状态会改变,但是在单击的时候还没有改变.这里打印的还是没有单击之前的状态结果.
            // 但是也不用去更新它的状态,重启之后,状态又回了.这里只需要去更新数据库即可.
            //Thread.Sleep(1000);
            //foreach (var item in viewModel.TotalModuleShieldedStates)
            //{
            //    LogHelper.WriteLog(LogType.Info, item.IsShielded.ToString());
            //}
            DataResult result = LocalDataAccess.UpdateModuleShieldedStateTb(boxName, isChecked);
            if (!result.State)
            {
                LogHelper.WriteLog(LogType.Fatal, result.Message);
            }
            else
            {
                LogHelper.WriteLog(LogType.Info, result.Message);
            }
        }
    }
}
